package com.tutorial.bf.service.impl;

import com.tutorial.bf.dao.UserDao;
import com.tutorial.bf.service.UserService;

import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class UserServiceImpl implements UserService {

    private String username;

    public void setUsername(String username) {
        this.username = username;
    }

    private List<String> stringList;

    public void setStringList(List<String> stringList) {
        this.stringList = stringList;
    }

    private List<UserDao> userDaos;

    public void setUserDaos(List<UserDao> userDaos) {
        this.userDaos = userDaos;
    }

    private Properties properties;

    public void setProperties(Properties properties) {
        this.properties = properties;
    }

    private Set<UserDao> userDaoSet;
    private Map<String, UserDao> userDaoMap;

    public void setUserDaoSet(Set<UserDao> userDaoSet) {
        this.userDaoSet = userDaoSet;
    }

    public void setUserDaoMap(Map<String, UserDao> userDaoMap) {
        this.userDaoMap = userDaoMap;
    }

    public void show() {
        System.out.println("username = " + username);
        System.out.println("stringList = " + stringList);
        System.out.println("userDaos = " + userDaos);
        System.out.println("userDaoMap = " + userDaoMap);
        System.out.println("userDaoSet = " + userDaoSet);
        System.out.println("properties = " + properties);

    }

    public void init() {
        // environment.getProperty("");
        System.out.println("初始化方法......");
    }

    public void destroy() {
        System.out.println("销毁方法......");
    }

    public UserServiceImpl() {
        System.out.println("UserServiceImpl的无参构造实例化啦！");
    }

    public UserServiceImpl(String name, Integer age) {
        System.out.println(age + "岁的" + name + "说: UserServiceImpl有参构造实例化啦！");
    }

    private UserDao userDao;

    // BeanFactory去调用该方法获得userDao设置到此处
    public void setUserDao(UserDao userDao) {
        System.out.println("属性设置完毕");
        this.userDao = userDao;
    }

    // 执行时机早于init-method配置的方法
//    @Override
//    public void afterPropertiesSet() throws Exception {
//        System.out.println("afterPropertiesSet执行啦......");
//    }
//
//    @Override
//    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
//        System.out.println("1setBeanFactory......");
//    }
}
